package com.love.marriage.commissionInfo.service.impl;

import com.love.marriage.commissionInfo.entity.CommissionInfo;
import com.love.marriage.commissionInfo.vo.CommissionInfoVo;
import com.love.marriage.commissionInfo.mapper.CommissionInfoMapper;
import com.love.marriage.commissionInfo.service.CommissionInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import com.love.marriage.utils.StringUtils;

/**
 * <p>
 * description:  佣金表服务实现类
 * author:       mybatisPlus
 * createDate:   2024-10-28 19:07:46
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class CommissionInfoServiceImp extends ServiceImpl<CommissionInfoMapper, CommissionInfo> implements CommissionInfoService {

    private final CommissionInfoMapper commissionInfoMapper;

    @Override
    public Page<CommissionInfoVo> getPage(Long pageNum, Long pageSize, CommissionInfoVo commissionInfoVo) {
        Page<CommissionInfoVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return commissionInfoMapper.getPage(page, commissionInfoVo);
    }

    @Override
    public CommissionInfoVo queryCommissionInfo(Long id) {
        return commissionInfoMapper.queryCommissionInfo(id);
    }

    @Override
    public CommissionInfoVo addCommissionInfo(CommissionInfoVo commissionInfoVo) {
        CommissionInfo commissionInfo = new CommissionInfo();
        BeanUtils.copyProperties(commissionInfoVo, commissionInfo);
        commissionInfoMapper.insert(commissionInfo);
        CommissionInfoVo res = new CommissionInfoVo();
        BeanUtils.copyProperties(commissionInfo, res);
        return res;
    }

    @Override
    public CommissionInfoVo updateCommissionInfo(CommissionInfoVo commissionInfoVo) {
        CommissionInfo commissionInfo = new CommissionInfo();
        BeanUtils.copyProperties(commissionInfoVo, commissionInfo);
        commissionInfoMapper.updateById(commissionInfo);
        return commissionInfoVo;
    }

    @Override
    public Boolean deleteCommissionInfo(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        commissionInfoMapper.deleteBatchIds(idArr);
        return true;
    }
}
